#ifndef PROVIDENT_EXPIRATION_HPP_
#define PROVIDENT_EXPIRATION_HPP_

#include <promote/HashMap.hpp>
#include <promote/Timestamp.hpp>

namespace provident
{
    class ExpiryCalculator
    {
    public:
        enum Type { 
            CALENDAR_YEAR, TRADING_YEAR
        };

        ExpiryCalculator(Type const type,
                         promote::Timestamp const& timestamp = promote::Timestamp());
        ExpiryCalculator(Type const type,
                         unsigned const nowMonth,
                         unsigned const nowDay,
                         unsigned const nowYear);
        ~ExpiryCalculator() { }

        double yearsTilExpiry(promote::Timestamp const& timestamp)
        {
            return yearsTilExpiry(timestamp.month(), timestamp.dayOfMonth(), timestamp.year());
        }

        double yearsTilExpiry(unsigned const month,
                              unsigned const day,
                              unsigned const year);

    private:
        static unsigned createKey(unsigned const month,
                                  unsigned const day,
                                  unsigned const year)
        {
            return (year << 12) | (month << 6) | day;
        }

        Type const _type;
        unsigned const _startMonth;
        unsigned const _startDay;
        unsigned const _startYear;
        promote::HashMap<unsigned,double> _history;
    };
}

#endif /* PROVIDENT_EXPIRATION_HPP_ */

